package gitlab_hook

import (
	"encoding/json"
	"fmt"
	"testing"
)

var issueData1 = `
{
    "object_kind": "issue",
    "event_type": "issue",
    "user": {
        "id": 5094,
        "name": "pan leiming",
        "username": "panleiming",
        "avatar_url": null,
        "email": "[REDACTED]"
    },
    "project": {
        "id": 20535,
        "name": "Learn GitLab",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "web_url": "https://jihulab.com/lingxi/learn-gitlab",
        "avatar_url": "https://jihulab.com/uploads/-/system/project/avatar/20535/Artboard.jpg",
        "git_ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "git_http_url": "https://jihulab.com/lingxi/learn-gitlab.git",
        "namespace": "lingxi",
        "visibility_level": 0,
        "path_with_namespace": "lingxi/learn-gitlab",
        "default_branch": "master",
        "ci_config_path": "",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "http_url": "https://jihulab.com/lingxi/learn-gitlab.git"
    },
    "object_attributes": {
        "author_id": 5094,
        "closed_at": null,
        "confidential": false,
        "created_at": "2022-04-16T19:23:16.650+08:00",
        "description": "At any point while using the free version of GitLab you can start a trial of GitLab Ultimate for free for 30 days. With a GitLab Ultimate trial, you'll get access to all of the most popular features across all of the paid tiers within GitLab. \n \n:white_check_mark: Reduce risk by requiring team leaders to approve merge requests.\n \n:white_check_mark: Ensure code quality with Multiple code reviews.\n \n:white_check_mark: Run your CI pipelines for up to 50,000 minutes (~9,500 CI builds).\n \n:white_check_mark: Plan and organize parallel development with multiple issue boards.\n  \n:white_check_mark: Report on the productivity of each team in your organization by using issue analytics. \n \n:white_check_mark: Dynamically scan Docker images for vulnerabilities before production pushes. \n \n:white_check_mark: Scan security vulnerabilities, license compliance and dependencies in your CI pipelines. \n \n:white_check_mark: Get alerted when your application performance degrades. \n \n:white_check_mark: And so much more, [you can view all the features here](https://about.gitlab.com/pricing/gitlab-com/feature-comparison/). \n \n## Next steps\n* [ ] [Click here to start a trial of GitLab Ultimate.](https://gitlab.com/-/trial_registrations/new?glm_content=user_onboarding_whats_in_paid_tiers&glm_source=gitlab.com)",
        "discussion_locked": null,
        "due_date": null,
        "id": 104673,
        "iid": 15,
        "last_edited_at": null,
        "last_edited_by_id": null,
        "milestone_id": null,
        "moved_to_id": null,
        "duplicated_to_id": null,
        "project_id": 20535,
        "relative_position": 7695,
        "state_id": 2,
        "time_estimate": 0,
        "title": "Start a free trial of GitLab Ultimate - no credit card required :rocket:",
        "updated_at": "2022-04-16T19:23:16.650+08:00",
        "updated_by_id": null,
        "weight": null,
        "url": "https://jihulab.com/lingxi/learn-gitlab/-/issues/15",
        "total_time_spent": 0,
        "time_change": 0,
        "human_total_time_spent": null,
        "human_time_change": null,
        "human_time_estimate": null,
        "assignee_ids": [
            5094
        ],
        "assignee_id": 5094,
        "labels": [
            {
                "id": 10772,
                "title": "Novice",
                "color": "#D1D100",
                "project_id": 20535,
                "created_at": "2022-04-16T19:23:15.589+08:00",
                "updated_at": "2022-04-16T19:23:15.589+08:00",
                "template": false,
                "description": null,
                "type": "ProjectLabel",
                "group_id": null
            }
        ],
        "state": "closed",
        "severity": "unknown"
    },
    "labels": [
        {
            "id": 10772,
            "title": "Novice",
            "color": "#D1D100",
            "project_id": 20535,
            "created_at": "2022-04-16T19:23:15.589+08:00",
            "updated_at": "2022-04-16T19:23:15.589+08:00",
            "template": false,
            "description": null,
            "type": "ProjectLabel",
            "group_id": null
        }
    ],
    "changes": {},
    "repository": {
        "name": "Learn GitLab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab"
    },
    "assignees": [
        {
            "id": 5094,
            "name": "pan leiming",
            "username": "panleiming",
            "avatar_url": null,
            "email": "[REDACTED]"
        }
    ]
}
`

var issueData2 = `
{
    "object_kind": "issue",
    "event_type": "issue",
    "user": {
        "id": 5094,
        "name": "pan leiming",
        "username": "panleiming",
        "avatar_url": null,
        "email": "[REDACTED]"
    },
    "project": {
        "id": 20535,
        "name": "Learn GitLab",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "web_url": "https://jihulab.com/lingxi/learn-gitlab",
        "avatar_url": "https://jihulab.com/uploads/-/system/project/avatar/20535/Artboard.jpg",
        "git_ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "git_http_url": "https://jihulab.com/lingxi/learn-gitlab.git",
        "namespace": "lingxi",
        "visibility_level": 0,
        "path_with_namespace": "lingxi/learn-gitlab",
        "default_branch": "master",
        "ci_config_path": "",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "ssh_url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "http_url": "https://jihulab.com/lingxi/learn-gitlab.git"
    },
    "object_attributes": {
        "author_id": 5094,
        "closed_at": null,
        "confidential": false,
        "created_at": "2022-04-16T19:23:16.650+08:00",
        "description": "At any point while using the free version of GitLab you can start a trial of GitLab Ultimate for free for 30 days. With a GitLab Ultimate trial, you'll get access to all of the most popular features across all of the paid tiers within GitLab. \n \n:white_check_mark: Reduce risk by requiring team leaders to approve merge requests.\n \n:white_check_mark: Ensure code quality with Multiple code reviews.\n \n:white_check_mark: Run your CI pipelines for up to 50,000 minutes (~9,500 CI builds).\n \n:white_check_mark: Plan and organize parallel development with multiple issue boards.\n  \n:white_check_mark: Report on the productivity of each team in your organization by using issue analytics. \n \n:white_check_mark: Dynamically scan Docker images for vulnerabilities before production pushes. \n \n:white_check_mark: Scan security vulnerabilities, license compliance and dependencies in your CI pipelines. \n \n:white_check_mark: Get alerted when your application performance degrades. \n \n:white_check_mark: And so much more, [you can view all the features here](https://about.gitlab.com/pricing/gitlab-com/feature-comparison/). \n \n## Next steps\n* [ ] [Click here to start a trial of GitLab Ultimate.](https://gitlab.com/-/trial_registrations/new?glm_content=user_onboarding_whats_in_paid_tiers&glm_source=gitlab.com)",
        "discussion_locked": null,
        "due_date": null,
        "id": 104673,
        "iid": 15,
        "last_edited_at": null,
        "last_edited_by_id": null,
        "milestone_id": null,
        "moved_to_id": null,
        "duplicated_to_id": null,
        "project_id": 20535,
        "relative_position": 7695,
        "state_id": 2,
        "time_estimate": 0,
        "title": "Start a free trial of GitLab Ultimate - no credit card required :rocket:",
        "updated_at": "2022-04-16T19:23:16.650+08:00",
        "updated_by_id": null,
        "weight": null,
        "url": "https://jihulab.com/lingxi/learn-gitlab/-/issues/15",
        "total_time_spent": 0,
        "time_change": 0,
        "human_total_time_spent": null,
        "human_time_change": null,
        "human_time_estimate": null,
        "assignee_ids": [
            5094
        ],
        "assignee_id": 5094,
        "labels": [
            {
                "id": 10772,
                "title": "Novice",
                "color": "#D1D100",
                "project_id": 20535,
                "created_at": "2022-04-16T19:23:15.589+08:00",
                "updated_at": "2022-04-16T19:23:15.589+08:00",
                "template": false,
                "description": null,
                "type": "ProjectLabel",
                "group_id": null
            }
        ],
        "state": "closed",
        "severity": "unknown"
    },
    "labels": [
        {
            "id": 10772,
            "title": "Novice",
            "color": "#D1D100",
            "project_id": 20535,
            "created_at": "2022-04-16T19:23:15.589+08:00",
            "updated_at": "2022-04-16T19:23:15.589+08:00",
            "template": false,
            "description": null,
            "type": "ProjectLabel",
            "group_id": null
        }
    ],
    "changes": {},
    "repository": {
        "name": "Learn GitLab",
        "url": "git@jihulab.com:lingxi/learn-gitlab.git",
        "description": "Learn how to use GitLab to support your software development life cycle.",
        "homepage": "https://jihulab.com/lingxi/learn-gitlab"
    },
    "assignees": [
        {
            "id": 5094,
            "name": "pan leiming",
            "username": "panleiming",
            "avatar_url": null,
            "email": "[REDACTED]"
        }
    ]
}
`

func TestIssueHook1(t *testing.T) {
	issueHook := &IssueHook{}
	err := json.Unmarshal([]byte(issueData1), issueHook)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	data, _ := json.MarshalIndent(issueHook, "  ", "  ")
	fmt.Println(string(data))
}
